package com.power.ding.runner.jobs;

import java.util.List;

import com.plf.common.utils.SpringHolder;
import com.power.ding.exception.DingException;
import com.power.ding.service.Di_messageService;
import com.power.ding.service.SystemService;

public class MessageJob implements Runnable{
	private static MessageJob self;
	
	private Di_messageService di_messageService;
	
	private SystemService systemService;

	public static MessageJob getInstance() {
		if(self==null) {
			self=new MessageJob();
		}
		
		return self;
	}

	public void run() {
		while(true) {
			di_messageService=SpringHolder.getBean(Di_messageService.class);
			systemService=SpringHolder.getBean(SystemService.class);
			
			List<String> list=di_messageService.findUnsendList();
			if(list!=null && list.size()>0) {
				for(String id : list) {
					try {
						systemService.sendMessage(id);
					} catch (DingException e) {
						e.printStackTrace();
					}
				}
			}
			
			try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				System.out.println("InterruptedException");
				e.printStackTrace();
			}
		}
	}

}
